<template>
  <div id="app">
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive" :key="key" />
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive" :key="key" />

    <!-- <beian v-if="isShow"></beian> -->
    <tabbar v-if="$route.meta.showTab" :isRefresh="refresh" />
    <!-- <Error :showTime="300000" /> -->
  </div>
</template>

<script>
const height = document.body.clientHeight
import Tabbar from './components/Tabbar'
import Beian from './components/beian/Beian.vue';
import Error from './components/error/error.vue';
import { mapGetters } from 'vuex';
export default {
  components: {
    Tabbar,
    Beian,
    Error
  },
  data() {
    return {
      // refresh:Boolean( sessionStorage.getItem('refresh')) || false
      form:'',
      showErrors:false,
      isShow:true
    }
  },
  computed: {
    ...mapGetters['errorImg'],
    showError(){
      console.log('errorImg===',this.$errorImg)
      return this.$errorImg
    },
    key() {
      return this.$route.fullPath
    },
    refresh() {
      return Boolean(sessionStorage.getItem('refresh')) || false
    }
  },
  watch: {
    errorImg:{
      handler:function(newVal) {
        console.log('showError=',newVal)
        this.showErrors =newVal
        // if(newVal){
        //   this.getCartGoodsCount()
        // }
      },
      immediate: true,
      deep:true
    }
  },
  created(){
    
    console.log('showError==',this.$errorImg)
    
  },
  mounted() {
    this.form = this.$route.query.from
    console.log('showError= mounted=',this.$errorImg)
    window.addEventListener('resize',()=>{
      // alert()
        if(document.body.clientHeight<height){
          // alert('进来了')
          this.isShow=false
        }else{
          this.isShow = true
        }
      })
    /*浏览器标签页切换会触发"visibilitychange"事件*/
    document.addEventListener("visibilitychange", e => {
      if (e.target.location.hostname == 'localhost') {
        return false
      }
      console.log(e)
      //切换显示标签
      // if(document.visibilityState === "visible"){
      //   Cookies.remove('token')
      //   Cookies.remove('Admin-Token')
      //   Cookies.remove('password')
      //   Cookies.remove('username')
      //   Cookies.remove('rememberMe')
      //   this.$router.push({name:'Login'})
      // }
    })
    /*浏览器关闭、浏览器标签页关闭、浏览器刷新均会触发"beforeunload"事件*/
    window.addEventListener('beforeunload', e => this.handleFn())

  },
  beforeDestroy() {
    // this.$root.$off('handle-401');
  }
}
</script>
<style scoped>
#app {
  position: relative;
  width: 100vw;
  min-height: 100vh;
  /* font-size: 16px !important; */
  /* background-color: #f0f0f0; */
}


</style>
